//
//  ConfigExt.swift
//  FlameB
//
//  Created by 连俊 on 2020/7/30.
//  Copyright © 2020 连俊. All rights reserved.
//

import UIKit

extension UIFont {
    static func mainFont(ofSize fontSize: CGFloat) -> UIFont {
        return UIFont.systemFont(ofSize:fontSize)
    }
    static func mainFontForTitle(ofSize fontSize: CGFloat) -> UIFont {
        return UIFont.systemFont(ofSize:fontSize)
    }
    
    
    ///思源宋体黑体
    static func singBoldFont(size fontSize: CGFloat)->UIFont{
        let f = UIFont(name: "SourceHanSerifCN-Bold", size: fontSize)
        guard let t = f else {
            return UIFont.systemFont(ofSize: fontSize, weight: UIFont.Weight.medium)
        }
        return t
    }
}

private struct AppScreenSize {
    static var screenWidth: CGFloat = 0
    static var screenHeight: CGFloat = 0
}

extension UIScreen {
    static func appHeight() -> CGFloat {
        if AppScreenSize.screenHeight > 0 {
            return AppScreenSize.screenHeight
        }

        AppScreenSize.screenHeight = max(main.bounds.width, main.bounds.height)
        return AppScreenSize.screenHeight
    }

    static func appWidth() -> CGFloat {
        if AppScreenSize.screenWidth > 0 {
            return AppScreenSize.screenWidth
        }

        AppScreenSize.screenWidth = min(main.bounds.width, main.bounds.height)
        return AppScreenSize.screenWidth
    }
}

extension UIColor {
    convenience init(rgb: UInt, alpha: CGFloat = 1) {
        self.init(red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0, blue: CGFloat(rgb & 0x0000FF) / 255.0, alpha: alpha)
    }
}


// 适配
var KScreenHeight: CGFloat {
    return UIScreen.appHeight()
}
var KScreenWidth: CGFloat {
    return UIScreen.appWidth()
}
var isIPhone6: Bool {
    return KScreenHeight == 667
}
var isIPhone6Plus: Bool {
    return KScreenHeight == 736
}
var isIPhoneX: Bool {
    let height = UIApplication.shared.statusBarFrame.size.height
    return height > 40
    //return KScreenHeight == 812
}
var isIPhone4: Bool {
    return KScreenHeight == 480
}
var isIPhone5: Bool {
    return KScreenHeight == 568
}

// navigationBarHeight
let navigationBarHeight : CGFloat = isIPhoneX ? 88 : 64

// tabBarHeight
let tabBarHeight : CGFloat = isIPhoneX ? 49 + 34 : 49

// 传进来 6s的尺寸
func GTSize_width(_ width: CGFloat) -> CGFloat {

    switch KScreenWidth {
    case 375:
        return width
    case 414:
        return width * 1.104
    case 320:
        return width * 0.85
    default:
        return width
    }
}
func GTSize_height(_ height: CGFloat) -> CGFloat {

    switch KScreenHeight {
    case 667: //6s 6
        return height
    case 736://plus
        return height * 1.10
    case 568: // 5
        return height * 0.85
    case 480://4
        return height * 0.71
    case 812: // X
        return height * 1.21
    default:
        return height
    }
}
